<?php
class Bemigo_Controller_Action_Helper_FacebookCookie extends Zend_Controller_Action_Helper_Abstract
{

	public function getFacebookCookie() {
		$args = array();
		$app_id = Zend_Registry::get("configuration")->facebook->app->id;
		$app_secret = Zend_Registry::get("configuration")->facebook->app->secret;
		if(isset($_COOKIE['fbs_' . $app_id])){
			parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
			ksort($args);
			$payload = '';
			foreach ($args as $key => $value) {
				if ($key != 'sig') {
					$payload .= $key . '=' . $value;
				}
			}
			if (md5($payload . $app_secret) != $args['sig']) {
				return null;
			}
		}
		return $args;
	}
}